package states 
{
	import assets.AssetsUI;
	import com.greensock.TweenLite;
	import flash.geom.Rectangle;
	import org.agony2d.Agony;
	import org.agony2d.notify.AEvent;
	import org.agony2d.view.AgonyUI;
	import org.agony2d.view.core.IComponent;
	import org.agony2d.view.puppet.NineScalePuppet;
	import org.agony2d.view.UIState;
	
public class NineScaleUIState extends UIState
{

	override public function enter():void
	{
		NineScalePuppet.addNineScaleData((new (AssetsUI.IMG_nineScaleA)).bitmapData, 'nineScaleA', 5)
		
		this.fusion.move(200,200)
		nineScale = new NineScalePuppet('nineScaleA', 400 * 0.1, 200 * 0.1)
		this.fusion.addElement(nineScale,50,50)
		
		nineScale.addEventListener(AEvent.PRESS, __onMouse)
		nineScale.addEventListener(AEvent.PRESS, __onStartDrag)
		nineScale.addEventListener(AEvent.RELEASE, __onMouse)
		nineScale.addEventListener(AEvent.RELEASE, __onStopDrag)
		nineScale.addEventListener(AEvent.OVER, __onMouse)
		nineScale.addEventListener(AEvent.LEAVE, __onMouse)
		nineScale.addEventListener(AEvent.MOVE, __onMouse)
		nineScale.addEventListener(AEvent.CLICK, __onMouse )
		nineScale.addEventListener(AEvent.DOUBLE_CLICK, __onMouse)
		nineScale.addEventListener(AEvent.START_DRAG, __onMouse)
		nineScale.addEventListener(AEvent.DRAGGING, __onMouse)
		nineScale.addEventListener(AEvent.STOP_DRAG,__onMouse)
		
		TweenLite.to(nineScale, 2, { width:400 , height:200 } )
	}
	
	override public function exit():void
	{
		TweenLite.killTweensOf(nineScale)
	}

	private var nineScale:NineScalePuppet
	
	private function __onMouse(e:AEvent):void
	{
		trace(e.type)
	}
	
	private function __onStartDrag(e:AEvent):void
	{
		(e.target as IComponent).startDrag(false, new Rectangle(100,100,Agony.stage.stageWidth - 200, Agony.stage.stageHeight - 200))
	}
	
	private function __onStopDrag(e:AEvent):void
	{
		(e.target as IComponent).stopDrag(true)
	}
}
}